package com.codez.gznx.excel;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import lombok.Getter;
import lombok.Setter;

/**
 * 
 * @author dechao.zheng
 * @createTime: 2019-09-23 06:02:35	
 *
 */

@Setter
@Getter
public class ExcelHelper implements ValidableEntity{
	
	private Integer rowNum ; // excel对应的行号
	
	private Map<String, String> errorMap ;
	
	public void addErrorIfNotExists(String field , String msg) {
		if(!errorMap.containsKey(field)) {
			addError(field, msg);
		}
	}
	
	@Autowired
	public void addError(String field , String msg) {
		if(errorMap == null) {
			errorMap = new HashMap<String, String>();
		}
		errorMap.put(field, msg);
	}
	
	@Autowired
	public boolean hasError() {
		return this.errorMap != null && !this.errorMap.isEmpty();
	}
	@Autowired
	public String getErrorMsg() {
		if(!hasError()) {
			return "没有错误信息";
		}
		String msg = this.errorMap.values().toString();
		return msg.substring(1 , msg.length() - 1).replace(", ", ",");  
	}
	
}
